<!DOCTYPE html>
<html>
<head><title>节点字段配置</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" id="bpm_theme" type="text/css" href="../../easyui/newtheme/bule/devclient.css">
    <script type="text/javascript" src="../../jscode/lang/zh_CN.js"></script>
    <script type="text/javascript" src="../../easyui/jquery.min.js"></script>
    <script type="text/javascript" src="../../easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../jscode/sharefunction.js"></script>
    <script type="text/javascript" src="../../jscode/json.js"></script>
    <script type="text/javascript" src="../../jscode/viewgrid.js"></script>
    <script>
        var FormNum = "", GridNum = "V_S002_E003";
        WF_Appid = "S029";

        var CONFIG = [];
        $.ajax({
            url: "../config/config.json",
            //同步请求
            async: false,
            type: 'GET',
            success: function (data) {
                CONFIG = data;
            }
        });

        $(function () {


            $('#dg').datagrid({
                method: 'GET',
                url: CONFIG.url.getEventRuleConfig,
            });

        })

        function formatlink(v, r) {
            return "<a href='' onclick=\"RowDblClick(0,'" + r.WF_OrUnid + "');return false;\" >" + v + "</a>";
        }

        function GroupFormat(value, rows) {
            return value + ' - ' + rows.length + ' 项';
        }

        $(window).resize(function () {
            $('#dg').datagrid('resize', {
                width: function () {
                    return document.body.clientWidth;
                }, height: function () {
                    return document.body.clientHeight;
                }
            });
        });

        /**
         * 保存提交
         * */
        function saveEditorGrid() {
            //获得所有修改的数据
            stopEditRow();
            var dg = $("#dg");

            //获得所有修改的数据
            var delRow = JSON.stringify(dg.datagrid('getChanges', 'deleted'));
            console.dir(GetUrlArg("Nodeid"))
            var rowData = dg.datagrid('getChanges', 'inserted');
            for (var i = 0; i < rowData.length; i++) {
                rowData[i].Processid = GetUrlArg("Processid");
                rowData[i].Nodeid = GetUrlArg("Nodeid");
            }

            var newRow = JSON.stringify(rowData);
            var editRow = JSON.stringify(dg.datagrid('getChanges', 'updated'));


            //保存修改结果
            mask();
            $.post(CONFIG.url.saveEventRuleConfig, {
                WF_Action: 'saveEditor',
                delRow: delRow,
                newRow: newRow,
                editRow: editRow
            }, function (data) {
                if (data.Status == "error") {
                    alert(data.msg);
                } else {
                    dg.datagrid('acceptChanges');
                }
                unmask();
            });
        }

        function insertRow() {
            //插入新行
            stopEditRow();
            var i = $('#dg').datagrid('getData').rows.length;
            $('#dg').datagrid('insertRow', {index: i, row: {}});
        }

        function removeSelectedRow() {
            //删除选中行
            stopEditRow();
            var rows = $('#dg').datagrid('getSelections');
            if (!rows || rows.length == 0) {
                $.messager.alert('提示', '请选择要删除的字段!', 'info');
                return;
            }
            $.messager.confirm('Confirm', '您确定要删除选中字段吗?', function (r) {
                if (r) {
                    var dg = $('#dg');
                    $.each(rows, function (i, row) {
                        var index = dg.datagrid('getRowIndex', row);
                        dg.datagrid('deleteRow', index);
                    });

                    saveEditorGrid();
                }
            });


        }

        var lastIndex;

        function RowClick(rowIndex) {
            //单击进行修改
            $("#dg").datagrid('unselectAll');
            $("#dg").datagrid('selectRow', rowIndex);
            if (lastIndex != rowIndex) {
                $('#dg').datagrid('endEdit', lastIndex);
                $('#dg').datagrid('beginEdit', rowIndex);
            }
            lastIndex = rowIndex;
        }

        function stopEditRow() {
            $('#dg').datagrid('endEdit', lastIndex);
            lastIndex = undefined;
        }


        /**
         * 保存字段设置
         * add by alibao 20201021
         */
        // function saveConfig() {
        //
        //     $('#dg').datagrid('acceptChanges');
        //     var rowdata = $('#dg').datagrid('getData');
        //     var j = 0;
        //     var postdata = {};
        //
        //     postdata.total = rowdata.rows.length;
        //     postdata.rows = rowdata.rows;
        //     postdata = JSON.stringify(postdata);
        //
        //
        //     $.post(CONFIG.url.saveEventRuleConfig, {formConfig: postdata},
        //         function (ed) {
        //             alert(ed.msg);
        //         }, "json");
        // }


        /**
         * 返回节点事件配置视图
         */
        function backurl() {
            window.history.back();
        }

        /**
         *
         * 更新事件配置
         */
        function updateConfig() {

            $.ajax({
                type: "GET",
                url: CONFIG.url.updateEventRuleConfig,
                success: function(ed){
                    alert(ed.msg);
                    $('#dg').datagrid('load');
                }
            });
        }


    </script>
</head>
<body>
<div class="toptoolbar" id="toptoolbar">
    <span style="float:right;padding-right:20px;margin-top: 7px;">搜索:<input class="easyui-searchbox" data-options="searcher:GridDoSearch,prompt:'输入关键字后回车...'" id="SearchKeyWord" style="width:150px;"/></span>-
    <a href="#" id="btnSave" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-add'" onclick="saveEditorGrid();return false;">保存设置</a> -
<!--    <a href="#" id="btnNew" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-add'" onclick="insertRow();return false;">新增</a> - -->
    <a href="#" id="btnDel" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-remove'" onclick="removeSelectedRow();return false;">删除字段</a> -
    <a href="#" id="btnupdate" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-ok'" onclick="updateConfig();return false;">更新事件配置</a> -
    <a href="#" id="btnback" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-back'" onclick="backurl();return false;">返回</a>
</div>

<table id="dg" class="easyui-datagrid"
       data-options="toolbar:toptoolbar,fit:true,autoRowHeight:false,remoteSort:false,border:false,rownumbers: true,fitColumns:true,singleSelect:false,multiSort:true,onDblClickRow:stopEditRow,onClickRow:RowClick,onRowContextMenu:stopEditRow,pagination:true,pageSize:25,pageList:[20,25,30,40,60]">
    <thead>
    <tr>
        <th data-options="checkbox:true"></th>
        <th data-options="field:'RuleNum',width:100,sortable:true,align:'center'">规则ID</th>
        <th data-options="field:'RuleName',width:120,sortable:true,editor:'text',align:'center'">规则名</th>
        <th data-options="field:'Folderid',width:150,sortable:true,align:'center',editor:{type:'combotree',options:{
              method:'GET',
              url:'../json/RuleSort.json'
            }}">所属分类
        </th>
        <th data-options="field:'ClassPath',width:120,sortable:true,align:'center'">类路径</th>
        <th data-options="field:'WF_DocCreated',width:85,sortable:true,align:'center'">创建时间</th>
    </thead>
</table>
<div id="win"></div>
</body>
</html>
